<template>
  <div>
    <el-form
      label-width="68px"
      :rules="userRules"
      :model="userInfo"
      ref="ruleFormRef"
    >
      <el-form-item label="账号" prop="name">
        <el-input v-model="userInfo.name"></el-input>
      </el-form-item>

      <el-form-item label="密码" prop="password">
        <el-input v-model="userInfo.password"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from "vue";
import { userRules } from "../config/rules-config";
import type { ElForm } from "element-plus";

export default defineComponent({
  setup() {
    const userInfo = reactive({
      name: "",
      password: ""
    });

    const ruleFormRef = ref<InstanceType<typeof ElForm>>();

    const loginStart = () => {
      console.log("loginStart validate");
      ruleFormRef.value?.validate((result) => {
        if (result) {
          console.log("loginStart");
        }
      });
    };

    return { userRules, userInfo, loginStart, ruleFormRef };
  }
});
</script>

<style scoped></style>
